import time
def show():
    print('请输入操纵：1.退出 2.查看登录日志')
def write_file(username):
    with open('user_log.text','a',encoding='utf-8') as file:
        s=f'用户名:{username},登录时间:{time.strftime("%Y-%m-%d %H-%M-%S",time.localtime(time.time()))}'
        file.write(s)
        file.write('\n')

def read_file():
    with open('user_log.text','r',encoding='utf-8') as file:
        while True:
            m=file.readline()
            if m=='':
                break
            else:
                print(m)

if __name__=='__main__':
    #write_file("admin")
    username=input('请输入用户名:')
    pwd=input('请输入密码:')
    if username=='mwy' and pwd=='123456':
        write_file(username)
        print('账号密码正确')
        x=eval(input(show()))
        while True:
            if x == 1:
                print('退出成功')
                break
            elif x == 2:
                print('查看日志')
                read_file()
            else:
                print('输入错误，请重新输入')
            x = eval(input(show()))
    else:
        print('账号或用户名不正确')



